<%--
  Created by IntelliJ IDEA.
  User: wangh
  Date: 2020/12/21
  Time: 15:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html lang="zh-CN">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <title>管理员注册</title>

    <!-- 1. 导入CSS的全局样式 -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="js/jquery-3.3.1.min.js"></script>
    <!-- 3. 导入bootstrap的js文件 -->
    <script src="js/bootstrap.min.js"></script>
    <script>
        function checkForm() {
            var nametip = checkUserName();
            var passtip = checkPassword();
            var conpasstip = checkRepeatPassword();
            var phonetip = checkPhone();
            return nametip && passtip && conpasstip && phonetip;
        }

        function checkUserName() {
            var username = document.getElementById('username');
            var errname = document.getElementById('nameErr');
            var pattern = /^\w{3,}$/;  //用户名格式正则表达式：用户名要至少三位
            if (username.value.length == 0) {
                errname.innerHTML = "用户名不能为空"
                errname.className = "error"
                return false;
            }
            if (!pattern.test(username.value)) {
                errname.innerHTML = "用户名要至少三位"
                errname.className = "error"
                return false;
            } else {
                errname.innerHTML = "OK"
                errname.className = "success";
                return true;
            }
        }

        function checkPassword() {
            var userpasswd = document.getElementById('password');
            var errPasswd = document.getElementById('passwordErr');
            var pattern = /^\w{4,16}$/; //密码要在4-16位
            if (!pattern.test(userpasswd.value)) {
                errPasswd.innerHTML = "密码不合规范,要4-16位"
                errPasswd.className = "error"
                return false;
            } else {
                errPasswd.innerHTML = "OK"
                errPasswd.className = "success";
                return true;
            }
        }

        function checkRepeatPassword() {
            var userpasswd = document.getElementById('password');
            var userConPassword = document.getElementById('repeatPassword');
            var errConPasswd = document.getElementById('conPasswordErr');
            if ((userpasswd.value) != (userConPassword.value) || userConPassword.value.length == 0) {
                errConPasswd.innerHTML = "上下密码不一致"
                errConPasswd.className = "error"
                return false;
            } else {
                errConPasswd.innerHTML = "OK"
                errConPasswd.className = "success";
                return true;
            }
        }

        function checkPhone() {
            var userphone = document.getElementById('phone');
            var phonrErr = document.getElementById('phoneErr');
            var pattern = /^1[34578]\d{9}$/; //验证手机号正则表达式
            if (!pattern.test(userphone.value)) {
                phonrErr.innerHTML = "手机号码不合规范"
                phonrErr.className = "error"
                return false;
            } else {
                phonrErr.innerHTML = "OK"
                phonrErr.className = "success";
                return true;
            }
        }
    </script>
</head>
<body style="background-color: #F2F2F2">
<%
    request.setCharacterEncoding("utf-8");
    request.getSession().setAttribute("requestUrl",request.getRequestURI());
%>
<div class="logoBar"
     style="height: 75px;background: #1d7ad9;font-size: 35px;font-weight: bolder;padding-left: 100px;padding-top: 12px;color: white;">
    电脑销售管理后台
</div>
<div class="container" style="width: 400px;background-color: #ffffff;margin-top: 20px;border-radius: 10px">
    <h3 style="text-align: center;">管理员注册</h3>
    <form action="${pageContext.request.contextPath}/registerServlet" method="post" onSubmit="return checkForm()">
        <div class="form-group">
            <label for="username">用户名：</label>
            <input type="text" name="username" class="form-control" id="username" placeholder="请输入用户名"
                   onBlur="checkUserName()" oninput="checkUserName()"/>
            <span id="nameErr"></span>
        </div>

        <div class="form-group">
            <label for="password">密码：</label>
            <input type="password" name="password" class="form-control" id="password" placeholder="请输入密码"
                   onBlur="checkPassword()" oninput="checkPassword()"/>
            <span id="passwordErr"></span>
        </div>

        <div class="form-group">
            <label for="repeatPassword">重复密码：</label>
            <input type="password" name="repeatPassword" class="form-control" id="repeatPassword" placeholder="请重复输入密码"
                   onBlur="checkRepeatPassword()" oninput="checkRepeatPassword()"/>
            <span id="conPasswordErr"></span>
        </div>

        <div class="form-inline">
            <label>性别：</label>
            <input type="radio" name="gender" value="男" checked="checked"/>男
            <input type="radio" name="gender" value="女">女
        </div>

        <div class="form-group">
            <label for="phone">手机号：</label>
            <input type="text" name="phone" class="form-control" id="phone" placeholder="请输入11位手机号"
                   onBlur="checkPhone()" oninput="checkPhone()"/>
            <span id="phoneErr"></span>
        </div>
        <div class="form-inline">
            <label>籍贯：</label>
            <select name="address">
                <option value="浙江">浙江</option>
                <option value="上海">上海</option>
                <option value="台湾">台湾</option>
                <option value="江苏">江苏</option>
            </select>
        </div>
        <hr/>
        <div class="form-group" style="text-align: center;">
            <input class="btn btn btn-primary" type="submit" value="注册" style="width: 100%;">
        </div>
    </form>
    <!-- 出错显示的信息框 -->
    <div class="alert alert-warning alert-dismissible" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span
                aria-hidden="true">&times;</span></button>
        <strong>提示信息:</strong>${register_message}
    </div>
</div>
</body>
</html>